<template>
  <div id="app" class="app-container">
    <h1>用户信息管理系统</h1>
    
    <div class="operation-buttons">
      <el-button type="primary" @click="handleAdd">新增用户</el-button>
      <el-button type="primary" @click="handleEdit">编辑用户</el-button>
      <el-button type="success" @click="handleView">查看用户</el-button>
    </div>
    
    <UserDialog 
      ref="userDialogRef" 
      :visible="dialogVisible" 
      :dialog-type="dialogType"
      :form-data="currentFormData"
      @update:visible="handleDialogVisibleChange"
      @submit="handleFormSubmit"
    />
  </div>
</template>

<script>
import { ref } from 'vue'
import UserDialog from './components/UserDialog.vue'

export default {
  name: 'App',
  components: {
    UserDialog
  },
  setup() {
    const userDialogRef = ref()
    const dialogVisible = ref(false)
    const dialogType = ref('add')
    const currentFormData = ref({})

    const handleAdd = () => {
      dialogType.value = 'add'
      currentFormData.value = {}
      dialogVisible.value = true
    }

    const handleEdit = () => {
      dialogType.value = 'edit'
      currentFormData.value = {
        user: 'ad001',
        Name: '张三',
        jslx: '烈火战士',
        lxName: '高级职业',
        Date: '2005-01-15 10:30:00',
        gender: 1,
        zt: 1,
        phone: '13800138000',
        email: '13800138000@qq.com',
        zzjg: 'hbdxzxxy'
      }
      dialogVisible.value = true
    }

    const handleView = () => {
      dialogType.value = 'view'
      currentFormData.value = {
        user: 'viewer001',
        Name: '李四',
        jslx: 'non-system',
        lxName: '普通职业',
        Date: '2006-11-11 11:11:11',
        gender: 2,
        zt: 1,
        phone: '13900139000',
        email: '235345@qq.com',
        zzjg: 'school'
      }
      dialogVisible.value = true
    }

    // 对话框可见性变化
    const handleDialogVisibleChange = (visible) => {
      dialogVisible.value = visible
    }

    // 表单提交处理
    const handleFormSubmit = (formData) => {
      console.log('表单提交数据:', formData)
      // 这里可以添加API调用等业务逻辑
      ElMessage.success(dialogType.value === 'add' ? '新增用户成功' : '编辑用户成功')
      dialogVisible.value = false
    }

    return {
      userDialogRef,
      dialogVisible,
      dialogType,
      currentFormData,
      handleAdd,
      handleEdit,
      handleView,
      handleDialogVisibleChange,
      handleFormSubmit
    }
  }
}
</script>

<style scoped>
.app-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.operation-buttons {
  margin: 20px 0;
}

.operation-buttons .el-button {
  margin-right: 10px;
}

h1 {
  color: #303133;
  text-align: center;
  margin-bottom: 30px;
}
</style>